
using System;
using Mono.Unix;
using Habazie.kf2.Core;
using Habazie.kf2.Events;

namespace Habazie.kf2.GUI
{
	
	
	public class NotifyIcon : Gtk.StatusIcon 
	{
		private EventBox m_box;
	
		
		public NotifyIcon(EventBox box) : base ()
		{
			this.Pixbuf = Gdk.Pixbuf.LoadFromResource ("pix_message.png");
			
			this.Activate += OnActivated;
//			this.PopupMenu += OnPopupMenu;
			
			m_box = box;
			m_box.Updated += OnUpdated;
			
			OnUpdated (this, null);
		}
		
		
		protected virtual void OnUpdated (object o, EventArgs args)
		{
			Event e = m_box.Peek ();
			if (e != null) {
				this.Visible = true;
				this.Tooltip =  String.Format (
						Catalog.GetPluralString ("One event in queue", "{0} events in queue", m_box.Count),
					m_box.Count);

//				if (m_box.Count == 1)
//					this.Tooltip = "One event in queue";
//				else
//					this.Tooltip = String.Format ("{0} events in queue", m_box.Count);
			} else {
				this.Visible = false;
				this.Tooltip = "talkative";
			}
		}
		
		
		protected virtual void OnActivated (object o, EventArgs args)
		{
			Event e = m_box.Peek ();
			if (e != null) {
				m_box.Process (e.Id);
			}			
		}

	}
}
